package com.wsoft.hr.pm.controller;

import com.github.pagehelper.PageInfo;
import com.wsoft.hr.pm.entity.HrPmActivityEntity;
import com.wsoft.hr.pm.query.activity.ActivityInsertQuery;
import com.wsoft.hr.pm.query.activity.ActivityListQuery;
import com.wsoft.hr.pm.query.activity.ActivityUpdateEnableQuery;
import com.wsoft.hr.pm.query.activity.ActivityUpdateQuery;
import com.wsoft.hr.pm.service.IHrPmActivityService;
import com.wsoft.response.ResponsePage;
import com.wsoft.response.ResponseResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 考核活动 前端控制器
 * @author zhanggukai
 * @since 2025年02月27日 08:49:37
 */
@RestController
@Tag(name = "考核活动")
@RequestMapping("/hr/pm/activity")
public class HrPmActivityController {
    @Resource
    private IHrPmActivityService activityService;

    @Operation(summary = "新增活动", description = "新增活动")
    @PostMapping("/insert")
    public ResponseResult insert(@RequestBody @Valid ActivityInsertQuery query) {
        boolean b = activityService.insert(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "编辑活动", description = "编辑活动")
    @PostMapping("/update")
    public ResponseResult update(@RequestBody @Valid ActivityUpdateQuery query) {
        boolean b = activityService.update(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "启用活动", description = "启用活动")
    @PostMapping("/enable")
    public ResponseResult enable(@RequestBody @Valid ActivityUpdateEnableQuery query) {
        boolean b = activityService.updateStatus(query);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }


    @Operation(summary = "活动详情", description = "活动详情")
    @GetMapping("/get")
    public ResponseResult get(@RequestParam("id") Long id) {
        return ResponseResult.success(activityService.get(id));
    }


    @Operation(summary = "删除活动", description = "删除活动")
    @GetMapping("/delete")
    public ResponseResult delete(@RequestParam("id") Long id) {
        boolean b = activityService.delete(id);
        if (b) {
            return ResponseResult.success("[sys.msg.success]");
        } else {
            return ResponseResult.failed("[sys.msg.failed]");
        }
    }

    @Operation(summary = "活动分页", description = "活动分页")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody ActivityListQuery query) {
        PageInfo<HrPmActivityEntity> page = activityService.pageList(query);
        return ResponseResult.success(ResponsePage.restPage(page));
    }

}
